package com.example.demo.common;

/**
 * @author bueryouth
 * @update 2021/8/6/00614:41
 * @date 返回结果配置文件
 */
public class Result<T> {
    /** 返回结果状态码 */
    private String codes;
    /** 返回结果信息 */
    private String msg;
    /** 返回结果数据 */
    private T data;

    public String getCodes() {
        return codes;
    }

    public void setCodes(String codes) {
        this.codes = codes;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Result() {}

    public Result(T data) {
        this.data = data;
    }

    public static <T> Result<T> success() {
        Result<T> result = new Result<>();
        result.setCodes("200");
        result.setMsg("成功");
        return result;
    }

    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<>(data);
        result.setCodes("200");
        result.setMsg("请求成功");
        return result;
    }

    public static <T> Result<T> error() {
        Result<T> result = new Result<>();
        result.setCodes("500");
        result.setMsg("请求失败");
        return result;
    }

    public static <T> Result<T> error(String code, String msg) {
        Result<T> result = new Result<>();
        result.setCodes(code);
        result.setMsg(msg);
        return result;
    }

    public static <T> Result<T> approve() {
        Result<T> result = new Result<>();
        result.setCodes("401");
        result.setMsg("请求未认证，跳转登陆页面！");
        return result;
    }

    public static <T> Result<T> authorization() {
        Result<T> result = new Result<>();
        result.setCodes("406");
        result.setMsg("请求未授权，跳转未授权提示页！");
        return result;
    }
}
